package com.egao.trade.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.trade.entity.TradeGoods;
import com.egao.trade.service.TradeGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 外贸商品
 * @author : Doman
 * @date : 2022-04-18 15:49:37
 * @version ：1.0
 */

@Api(tags = "外贸商品")
@RestController
@RequestMapping("/api/trade/tradeGoods")
public class TradeGoodsController extends BaseController {

	@Autowired
	private TradeGoodsService tradeGoodsService;

	/**
	 * 分页查询列表
	 */
//	@PreAuthorize("hasAuthority('trade:tradeGoods:list')")
  @ApiOperation(value ="分页查询外贸商品",notes = "" +
    "limit:每页显示几行 必填\n" +
    "page:第几页 必填\n" +
    " \n\n\n" +
    "返回的结果:\n" +
    "id:id\n" +
    "type1:分类1\n" +
    "type2:分类2\n" +
    "picUrl:图片url\n" +
    "describes:物品描述\n" +
    "refPrice:参考价格\n" +
    "leastOrder:最少起订量\n" +
    "payment:支付方式\n" +
    "goodsSize:尺寸\n" +
    "limitUse:使用范围\n" +
    "color:颜色\n" +
    "nums:数量\n" +
    "price:价格\n" +
    "freight:运费\n" +
    "orderNum:排序\n" +
    "createTime:创建时间\n" +
    "createUser:创建人\n" +
    "updateTime:更新时间\n" +
    "updateUser:更新人\n" +
    "",httpMethod = "POST")
  @ApiPageParam
  @PostMapping("/list")
  public JsonResult page(PageResult2<T> page, TradeGoods tradeGoods) throws Exception{
    return tradeGoodsService.list(page, tradeGoods, getLoginUser());
  }

  /**
   * 查询全部外贸商品
   */
//  @PreAuthorize("hasAuthority('trade:tradeGoods:list')")
  @ApiOperation("查询全部外贸商品")
  @PostMapping("/listAll")
  public JsonResult list(TradeGoods tradeGoods){
    return tradeGoodsService.list(tradeGoods, getLoginUser());
  }

  /**
   * 根据id查询外贸商品
   */
//  @PreAuthorize("hasAuthority('trade:tradeGoods:list')")
  @ApiOperation("根据id查询外贸商品")
  @PostMapping("/get")
  public JsonResult get(TradeGoods tradeGoods) {
    return tradeGoodsService.getById(tradeGoods);
  }


  /**
   * 添加外贸商品
   */
//  @PreAuthorize("hasAuthority('trade:tradeGoods:save')")
  @OperLog(value = "外贸商品", desc = "添加", param = false, result = true)
  @ApiOperation(value ="添加外贸商品",notes = "" +
    "type1:分类1\n" +
    "type2:分类2\n" +
    "picUrl:图片url\n" +
    "describes:物品描述\n" +
    "refPrice:参考价格\n" +
    "leastOrder:最少起订量\n" +
    "payment:支付方式\n" +
    "goodsSize:尺寸\n" +
    "limitUse:使用范围\n" +
    "color:颜色\n" +
    "nums:数量\n" +
    "price:价格\n" +
    "freight:运费\n" +
    "orderNum:排序\n" +
    "",httpMethod = "POST")
  @PostMapping("/save")
  public JsonResult save(Model model, TradeGoods tradeGoods) {
    return tradeGoodsService.save(tradeGoods, getLoginUser());
  }

  /**
   * 修改外贸商品
   */
//  @PreAuthorize("hasAuthority('trade:tradeGoods:update')")
  @OperLog(value = "外贸商品", desc = "修改", param = false, result = true)
  @ApiOperation(value ="修改外贸商品",notes = "" +
    "id:id\n" +
    "type1:分类1\n" +
    "type2:分类2\n" +
    "picUrl:图片url\n" +
    "describes:物品描述\n" +
    "refPrice:参考价格\n" +
    "leastOrder:最少起订量\n" +
    "payment:支付方式\n" +
    "goodsSize:尺寸\n" +
    "limitUse:使用范围\n" +
    "color:颜色\n" +
    "nums:数量\n" +
    "price:价格\n" +
    "freight:运费\n" +
    "orderNum:排序\n" +
    "",httpMethod = "POST")
  @PostMapping("/update")
  public JsonResult update(Model model, TradeGoods tradeGoods) {
    return tradeGoodsService.update(tradeGoods, getLoginUser());
  }

  /**
   * 删除外贸商品
   */
//  @PreAuthorize("hasAuthority('trade:tradeGoods:remove')")
  @OperLog(value = "外贸商品", desc = "删除", result = true)
  @ApiOperation(value ="删除外贸商品",notes = "" +
    "id:id\n" +
    "",httpMethod = "POST")
  @PostMapping("/remove")
  public JsonResult remove(TradeGoods tradeGoods ) {
    return tradeGoodsService.remove(tradeGoods, getLoginUser());
  }

}
